package com.yjk1.example.myFirstSofawebBoot;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

/**
 * @author yujiakui
 * @version 1.0
 * Email: jkyu@haiyi-info.com
 * date: 2018/11/9 11:05
 * description：动态编译java
 **/
public class FirstDynamicCompileJavaFile {

    public static void main(String[] args) {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        int result = compiler.run(null,null,null,"E:\\open-source-prj\\myFirstSofawebBoot\\src\\main\\java\\com\\yjk1\\example\\myFirstSofawebBoot\\FirstDynamicCompileJavaFile.java");
        System.out.println(result==0?"编译成功":"编译失败");
    }
}
